

  cmake_minimum_required(VERSION 3.12...3.14 FATAL_ERROR)
  project(GTC)

  #options
  option(GTC_ENABLE_CUDA "Enable CUDA" OFF)

  if(GTC_ENABLE_CUDA)
    enable_language(CUDA)
  endif()

  #-----------------------------------------------------------
  add_library(gtc_compiler_flags INTERFACE)
  target_compile_features(gtc_compiler_flags
                          INTERFACE cxx_std_11)
  set(CMAKE_CXX_EXTENSIONS Off)

  #-----------------------------------------------------------
  add_library(developer_flags INTERFACE)
  set(cxx_flags -Wall)
  set(cuda_flags -arch=sm_60 -Xcompiler=-Wall -Xcudafe=--display_error_number)
  target_compile_options(developer_flags INTERFACE
    # Flags for CXX builds
    $<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>
    # Flags for CUDA builds
    $<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags}>
  )
  target_link_libraries(gtc_compiler_flags INTERFACE
    $<BUILD_INTERFACE:developer_flags>)

  #-----------------------------------------------------------
  add_library(gtc_lib STATIC)
  target_sources(gtc_lib PRIVATE serial.cxx)
  if(GTC_ENABLE_CUDA)
    target_sources(gtc_lib PRIVATE parallel.cu)
  endif()

  set_target_properties(gtc_lib PROPERTIES
                        POSITION_INDEPENDENT_CODE ON
                        CUDA_SEPARABLE_COMPILATION ON)


  #-----------------------------------------------------------
  target_link_libraries(gtc_lib PUBLIC gtc_compiler_flags)
  target_include_directories(gtc_lib
    PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
    INTERFACE $<INSTALL_INTERFACE:include/gtc>)

  #-----------------------------------------------------------
  add_executable(gtc)
  target_sources(gtc PRIVATE main.cxx)
  target_link_libraries(gtc PRIVATE gtc_lib)

  #-----------------------------------------------------------
  install(TARGETS gtc gtc_lib gtc_compiler_flags
          EXPORT gtc-targets) #DESTINATION is automatic in 3.14
  install(EXPORT gtc-targets
          NAMESPACE gtc::
          DESTINATION lib/cmake/gtc)

  #-----------------------------------------------------------
  include(CMakePackageConfigHelpers)
  configure_package_config_file(ConfigTemplate.cmake.in
	  "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/gtc/GTCConfig.cmake"
     INSTALL_DESTINATION lib/cmake/gtc)
  install(
    FILES
    "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/gtc/GTCConfig.cmake"
    DESTINATION lib/cmake/gtc)
